{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Executing a Workflow (Lattice)\n",
    "\n",
    "To execute a lattice, use the Covalent `dispatch()` function.\n",
    "\n",
    "### Prerequisites\n",
    "\n",
    "1. [Start](./covalent_cli.rst) the Covalent services.\n",
    "\n",
    "2. Construct a workflow using the `@lattice` decorator:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import covalent as ct\n",
    "\n",
    "@ct.electron\n",
    "def identity(x):\n",
    "    return x\n",
    "\n",
    "@ct.electron\n",
    "def square(x):\n",
    "    return x * x\n",
    "\n",
    "@ct.lattice\n",
    "def workflow(a):\n",
    "    val_1 = identity(x=a)\n",
    "    return square(x=val_1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Procedure\n",
    "\n",
    "Submit the workflow using the `dispatch()` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19616db4-6b26-47ee-b340-449e51e606d7\n"
     ]
    }
   ],
   "source": [
    "dispatch_id = ct.dispatch(workflow)(a=2)\n",
    "print(dispatch_id)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When the server dispatches a workflow, it generates a dispatch ID. Use the ID to query the status of the task and retrieve the results as discussed in [Querying the Status of an Electron](../status/query_electron_execution_status.ipynb) and [Querying the Status of a Lattice](../status/query_lattice_execution_status.ipynb).\n",
    "\n",
    "### See Also\n",
    "\n",
    "[Constructing a Task (Electron)](../coding/construct_electron.ipynb)\n",
    "\n",
    "[Constructing a Workflow (Lattice)](../coding/construct_lattice.ipynb)\n",
    "\n",
    "[Adding an Electron to a Lattice](../coding/add_electron_to_lattice.ipynb)\n",
    "\n",
    "[Managing the Covalent Server](./covalent_cli.rst)\n",
    "\n",
    "[Querying the Status of an Electron](../collection/query_electron_execution_result.ipynb)\n",
    "\n",
    "[Querying the Status of a Lattice](../collection/query_lattice_execution_result.ipynb)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
